import { observable, action, toJS, computed } from 'mobx';
import { message } from 'antd';
import * as api from '../../apis/portrait/yearInventory';
import { WeaTableNew } from 'comsMobx';
const { TableStore } = WeaTableNew;
import { WeaLocaleProvider, WeaTools } from 'ecCom';
import { idsAndNamesToArr, getWeekOfYear } from '../../util/Util'
const getLabel = WeaLocaleProvider.getLabel;
export default class YearInventoryStore {

    @observable loading = true; // 页面初始化的loading状态：数据加载成功前后前使用

    @observable yearInventoryValue = []
    @observable yearList = []//年度盘点列表
    @observable username = ''

    @computed get scheduleData(){
        return this.filterByModuleId(1);
    }
    @computed get wfData(){
        return this.filterByModuleId(2);
    }
    @computed get docData(){
        return this.filterByModuleId(3);
    }
    @computed get messageData(){
        return this.filterByModuleId(4);
    }
    

    filterByModuleId=(moduleid)=>{
        return this.yearInventoryValue.filter((v)=>{return v.moduleid==moduleid});
    }

    @action('设置属性')
    setData = (value, type, callback) => {
        this.data[type] = value;
        if (callback) {
            setTimeout(() => {
                callback();
            }, 50);
        }
    };


    //获取年度盘点数据
    @action('获取年度盘点数据')
    getYearInventoryValue = params => {
        this.loading = true
        api.getYearInventoryValue(params).then(
            action(res => {
                if (res.api_status) {
                    this.yearInventoryValue = res.data
                    this.username = res.username
                    this.loading = false;
                } else {
                    message.error(res.msg || getLabel('383746', '请求失败'));
                }
            })
        );
    };

    //获取年度盘点列表
    @action('获取年度盘点列表')
    getYearInventoryList = params => {
        this.loading = true
        api.getYearInventoryList(params).then(
            action(res => {
                if (res.api_status) {
                    this.yearList = res.data
                    this.loading = false;
                } else {
                    message.error(res.msg || getLabel('383746', '请求失败'));
                }
            })
        );
    };


}
